import Vue from 'vue'
import Router from 'vue-router'
import Index from '@/view/index'
import App from '../App.vue'
import store from '@/store'
import {Message} from 'element-ui'
const Notice = () => import('@/view/notice')
const PreSell = () => import('@/view/preSell')
const GameList = () => import('@/view/gameList')
const WinerList = () => import('@/view/winerList')

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'app',
      // component: Index,
      component: App,
      children: [
        {
          path: '/',
          name: 'index',
          component: Index,
          meta: {
            // keepAlive: true,
            // login: true
          }
        },
        {
          name: 'notice',
          path: 'notice',
          component: Notice
        },
        {
          name: 'preSell',
          path: 'preSell',
          component: PreSell
        },
        {
          name: 'gameList',
          path: 'gameList',
          component: GameList
        },
        {
          name: 'winerList',
          path: 'winerList',
          component: WinerList
        }
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (!store.state.eosConfig && to.matched.some(record => record.meta.needConnectNet)) {
    Message.warning('此选项需要先进行网络设置！')
    next({
      path: '/setting',
      query: { redirect: to.fullPath }
    })
  } else {
    next()
  }
})

router.afterEach((to, from) => {
})

export default router
